package com.hly.musicbackground.model.index.rest;

import com.hly.musicbackground.Final.SearchFinal;
import com.hly.musicbackground.model.music.VO.MusicListVO;
import com.hly.musicbackground.model.music.params.SearchKeyParams;
import com.hly.musicbackground.result.Code;
import com.hly.musicbackground.result.Result;
import com.hly.musicbackground.model.index.service.SearchKeyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;


/**
 * 搜索
 * */
@RestController
@RequestMapping("/api/search")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Api(tags = "搜索")
public class SearchController {

    private final SearchKeyService searchKeyService;

    /**
     * 通过关键字进行搜索
     * @param keyParams 搜索的关
     * @param page 页数
     * @param limit 一页的数量
     * */
    @GetMapping("/key")
    @ApiOperation(value = "通过关键字进行搜索")
    public Result<Object> searchKey(@Valid SearchKeyParams keyParams,
                            @RequestParam(defaultValue = "1") int page,
                            @RequestParam(defaultValue = "10") int limit,
                            @RequestParam(defaultValue = SearchFinal.WHOLE) String type,
                            @RequestParam(defaultValue = "song") String aggregate){

        return Result.ok(searchKeyService.searchKey(aggregate, keyParams.getKey(), type, page, limit));
    }

    /**
     * 获取热门搜索关键字
     * */
    @GetMapping("/hotKey")
    @ApiOperation(value = "获取热门搜索关键字")
    public Result<List<String>> hotKey(@RequestParam(defaultValue = "song") String type){
        return Result.ok(searchKeyService.hotSearchKey(10, type));
    }

    /**
     * 获取可能要搜索的关键字
     * @param keyParams 搜索的关键字
     * */
    @GetMapping("/probablyKey")
    @ApiOperation(value = "获取可能要搜索的关键字")
    public Result<MusicListVO> probablyKey(SearchKeyParams keyParams,
                                           @RequestParam(defaultValue = "song") String type){
        return Result.ok();
    }
}
